<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="提现金额" prop="cashFee">
      <el-input v-model="dataForm.cashFee" placeholder="提现金额"></el-input>
    </el-form-item>
    <el-form-item label="1 删除;2 没有删除" prop="isDelete">
      <el-input v-model="dataForm.isDelete" placeholder="1 删除;2 没有删除"></el-input>
    </el-form-item>
    <el-form-item label="创建日期" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建日期"></el-input>
    </el-form-item>
    <el-form-item label="1 提现成功,0 提现审核中,2 提现失败" prop="state">
      <el-input v-model="dataForm.state" placeholder="1 提现成功,0 提现审核中,2 提现失败"></el-input>
    </el-form-item>
    <el-form-item label="1 管理员;2 校园代理;3 代理子账户;4 普通账户" prop="dtype">
      <el-input v-model="dataForm.dtype" placeholder="1 管理员;2 校园代理;3 代理子账户;4 普通账户"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="mark">
      <el-input v-model="dataForm.mark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          cashFee: '',
          isDelete: '',
          createTime: '',
          state: '',
          dtype: '',
          mark: ''
        },
        dataRule: {
          cashFee: [
            { required: true, message: '提现金额不能为空', trigger: 'blur' }
          ],
          isDelete: [
            { required: true, message: '1 删除;2 没有删除不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建日期不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '1 提现成功,0 提现审核中,2 提现失败不能为空', trigger: 'blur' }
          ],
          dtype: [
            { required: true, message: '1 管理员;2 校园代理;3 代理子账户;4 普通账户不能为空', trigger: 'blur' }
          ],
          mark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/bbl/cashrecord/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.cashFee = data.cashRecord.cashFee
                this.dataForm.isDelete = data.cashRecord.isDelete
                this.dataForm.createTime = data.cashRecord.createTime
                this.dataForm.state = data.cashRecord.state
                this.dataForm.dtype = data.cashRecord.dtype
                this.dataForm.mark = data.cashRecord.mark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/bbl/cashrecord/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'cashFee': this.dataForm.cashFee,
                'isDelete': this.dataForm.isDelete,
                'createTime': this.dataForm.createTime,
                'state': this.dataForm.state,
                'dtype': this.dataForm.dtype,
                'mark': this.dataForm.mark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
